//
//  TYTopNextController.m
//  爱鲜蜂
//
//  Created by 李田 on 16/11/19.
//  Copyright © 2016年 tianyao. All rights reserved.
//

#import "LBTopNextController.h"

@interface LBTopNextController ()

@end

@implementation LBTopNextController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)setupUI{
    
    self.view.backgroundColor = [UIColor cz_randomColor];
    
    
    UIBarButtonItem *rightBtnItem = [self barButtonItemWithImageName:@"v2_refresh" tag: kReloadDataButton];
    
    UIBarButtonItem *leftBtnItem = [self barButtonItemWithImageName:@"v2_goback" tag: kBackButton];
    [self.navigationItem setRightBarButtonItem:rightBtnItem];
    
    
    [self.navigationItem setLeftBarButtonItem:leftBtnItem];
}

- (UIBarButtonItem *)barButtonItemWithImageName: (NSString *)imageName tag: (TYNextVcTag)tag{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    
    btn.frame = CGRectMake(0, 0, 30, 30);
    
    UIBarButtonItem *btnItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    [btn addTarget:self action:@selector(reloadDataBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    
    
    btn.tag = tag;
    return btnItem;
    
}

- (void)reloadDataBtnClick: (UIBarButtonItem *)btnItem{
    switch (btnItem.tag) {
        case kBackButton:
            
            [self.navigationController popViewControllerAnimated:YES];
//            NSLog(@"返回");
            break;
            case kReloadDataButton:
            
            [self loadView];
//            NSLog(@"刷新");
        default:
            break;
    }
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
